/**
 * 初始化招聘管理详情对话框
 */
var JobInfoDlg = {
    jobInfoData : {},
    ueditor1: null,
    ueditor2: null,
    ueditor3: null
};

/**
 * 清除数据
 */
JobInfoDlg.clearData = function() {
    this.jobInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
JobInfoDlg.set = function(key, val) {
    this.jobInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
JobInfoDlg.get = function(key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
JobInfoDlg.close = function() {
    parent.layer.close(window.parent.Job.layerIndex);
}

/**
 * 收集数据
 */
JobInfoDlg.collectData = function() {
    this.jobInfoData['duty'] = JobInfoDlg.ueditor1.getContent();
    this.jobInfoData['requirement'] = JobInfoDlg.ueditor2.getContent();
    this.jobInfoData['welfare'] = JobInfoDlg.ueditor3.getContent();
    this
    .set('id')
    .set('name')
    .set('count')
    .set('workYear')
    .set('education')
    .set('workplace')
    .set('salary')
    .set('createTime')
    .set('updateTime')
    .set('isDel');
}

/**
 * 提交添加
 */
JobInfoDlg.addSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/jobMgr/add", function(data){
        Feng.success("添加成功!");
        window.parent.Job.table.refresh();
        JobInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.jobInfoData);
    ajax.start();
}

/**
 * 提交修改
 */
JobInfoDlg.editSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/jobMgr/update", function(data){
        Feng.success("修改成功!");
        window.parent.Job.table.refresh();
        JobInfoDlg.close();
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.jobInfoData);
    ajax.start();
}

$(function() {

    //实例化baidu编辑器
    var ueditor1 = UE.getEditor('ueditor1');
    JobInfoDlg.ueditor1 = ueditor1;
    var ueditor2 = UE.getEditor('ueditor2');
    JobInfoDlg.ueditor2 = ueditor2;
    var ueditor3 = UE.getEditor('ueditor3');
    JobInfoDlg.ueditor3 = ueditor3;

    ueditor1.ready(function(){
        ueditor1.setContent($("#dutyVal").val());
    });

    ueditor2.ready(function(){
        ueditor2.setContent($("#requirmentVal").val());
    });

    ueditor3.ready(function(){
        ueditor3.setContent($("#welfareVal").val());
    });

});
